home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / dxcmds34.sit / Dartmouth XCMD's 3.4.3 / card_12248.txt < prev    next >
Text File  |  1990-04-17  |  4KB  |  143 lines

  1. -- card: 12248 from stack: in.3
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 3241
  5. -- name: ObjectExists
  6. ----- HyperTalk script -----
  7. on Install
  8.   get ChooseTargetStack()
  9.   InstallResource XFCN,ObjectExists,it
  10. end Install
  11.  
  12.  
  13. -- part 1 (field)
  14. -- low flags: 81
  15. -- high flags: 2007
  16. -- rect: left=12 top=26 right=298 bottom=491
  17. -- title width / last selected line: 0
  18. -- icon id / first selected line: 0 / 0
  19. -- text alignment: 0
  20. -- font id: 22
  21. -- text size: 10
  22. -- style flags: 0
  23. -- line height: 13
  24. -- part name: Source
  25.  
  26.  
  27. -- part 2 (button)
  28. -- low flags: 00
  29. -- high flags: A003
  30. -- rect: left=299 top=300 right=322 bottom=438
  31. -- title width / last selected line: 0
  32. -- icon id / first selected line: 0 / 0
  33. -- text alignment: 1
  34. -- font id: 0
  35. -- text size: 12
  36. -- style flags: 0
  37. -- line height: 16
  38. -- part name: Show Pascal Source
  39. ----- HyperTalk script -----
  40. on mouseUp
  41.   set the visible of card field 1 to not the visible of card field 1
  42.   if the visible of card field 1 is true then
  43.     set the name of me to "Hide Pascal Source"
  44.   else set the name of me to "Show Pascal Source"
  45. end mouseUp
  46.  
  47.  
  48.  
  49. -- part contents for background part 16
  50. ----- text -----
  51. OBJECTEXISTS XFCN version 1.0
  52. Kevin Calhoun
  53.  
  54. ObjectExists determines whether or not a HyperCard object exists.  The bad news is that it's not perfect, for three reasons:
  55.  
  56. 1) If you want to ask by name (rather than by id or number) about an object with a short name longer than one word, you have to store the long name of the object in a container and then pass the container to ObjectExists.  For instance, to find out about card button "Show Pascal Source", you can use the following HyperTalk code:
  57.  
  58.     put "card btn" && quote & "Show Pascal Source" & quote into theButton
  59.     get ObjectExists(theButton)
  60.  
  61. This is an instance of the general problem of quoting in HyperCard.
  62.  
  63. 2)  If you want to find out whether a stack exists and the stack does not exist in any directory contained in the current Home stack's "Look for stacks inΓǪ" field, HyperCard will invoke the standard file package and ask the user to find the stack.  If the user selects a stack from the standard file dialog, ObjectExists returns TRUE whether or not the user selected the stack you designated.  If the user presses Cancel, ObjectExists returns FALSE, regardless of whether the stack is actually on the disk.
  64.  
  65. 3) In versions of HyperCard earlier than 1.2, it causes the dreaded "Never heard ofΓǪ" dialog box to appear when the object you designate does not exist.
  66.  
  67. INVOKING OBJECTEXISTS
  68.  
  69. get ObjectExists(objectDesignation)
  70.  
  71. result:  true or false
  72.  
  73. EXAMPLES
  74.  
  75. get ObjectExists("card field Watusi")
  76. get ObjectExists("bg btn 15")
  77. get ObjectExists("card id 2731")
  78. get ObjectExists("stack Home")
  79. get ObjectExists("background WildCard")
  80.  
  81.  
  82. -- part contents for card part 1
  83. ----- text -----
  84. UNIT BecauseRogerAskedForIt;
  85. { This XFCN requires HyperCard 1.2 or later }
  86.  
  87. { ObjectExists XFCN ┬⌐1989 by the Trustees of Dartmouth College }
  88. { Written by Kevin Calhoun }
  89.  
  90. { This source compatible with MPW Pascal 3.0 }
  91.  
  92. (*
  93. Pascal ObjectExists.p
  94. Link -m ENTRYPOINT Γêé
  95.      -o "YourFile" Γêé
  96.      -rt XFCN=19051 Γêé
  97.      -sn Main=ObjectExists Γêé
  98.      ObjectExists.p.o Γêé
  99.     "{Libraries}"interface.o Γêé
  100.     "{PLibraries}"Paslib.o Γêé
  101.     "{Libraries}"HyperXLib.o
  102. *)
  103.  
  104. {$R-}
  105.  
  106. interface
  107.   USES
  108.     Types,
  109.     Memory,
  110.     HyperXCmd;
  111.  
  112.   PROCEDURE EntryPoint (paramPtr : XCMDPtr);
  113.  
  114. IMPLEMENTATION
  115.  
  116. {-----------------------------------------------------------------}
  117.  
  118.   PROCEDURE ObjectExists (paramPtr: XCMDPtr);  FORWARD;
  119.  
  120.   PROCEDURE EntryPoint (paramPtr : XCMDPtr);
  121.   BEGIN
  122.     ObjectExists(paramPtr);
  123.   END;
  124.  
  125.   PROCEDURE ObjectExists (paramPtr: XCMDPtr);
  126.     VAR
  127.       s: Str255;
  128.       h: Handle;
  129.   BEGIN
  130.     IF paramPtr^.paramCount > 0 THEN
  131.       BEGIN
  132.       ZeroToPas(paramPtr, paramPtr^.params[1]^, s);
  133.       h := EvalExpr(paramPtr, CONCAT('the name of ',s));
  134.       BoolToStr(paramPtr,(paramPtr^.result = noErr), s);
  135.       paramPtr^.returnValue := PasToZero(paramPtr, s);
  136.       IF h <> NIL THEN DisposHandle(h);
  137.       END
  138.     ELSE
  139.       paramPtr^.returnValue :=
  140.         PasToZero(paramPtr, 'ObjectExists XFCN 1.0, 15 March 1989, ┬⌐1989 Dartmouth College');
  141.   END;
  142.   
  143. END.